<template>
  <div class="aui-card-list">
  <uni-list-query-card :queryShow="queryShow" @query-click="getDataList()" @click="(e)=>{this.queryShow=e}" @searchReset="searchReset()">
      <el-col :span="6">
        <el-form-item label="片段编码">
          <el-input v-model="dataForm.snippetCode" placeholder="片段编码" clearable></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="片段名称">
          <el-input v-model="dataForm.snippetName" placeholder="片段名称" clearable></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="片段类型">
            <el-select v-model="dataForm.snippetType" placeholder="片段类型" clearable>
              <el-option v-for="template in $getDictList('GEN_TEMP_APP_TYPE', true)" :key="template.val"
                :label="template.label" :value="template.val"></el-option>
            </el-select>
          </el-form-item>
      </el-col>
  </uni-list-query-card>
    <el-card shadow="never" class="aui-card-list-body">
      <vxe-toolbar setting>
        <template v-slot:buttons>
          <el-button v-if="$hasPermission('gen:genCodeSnippet:save')" type="primary" @click="addOrUpdateHandle()">
            {{ $t('add') }}
          </el-button>
          <el-button v-if="$hasPermission('gen:genCodeSnippet:delete')" type="danger" @click="deleteHandle()">
            {{ $t('deleteBatch') }}
          </el-button>
        </template>
        <template v-slot:tools>
          <el-button icon="el-icon-search" @click="searchShowHandle()" circle></el-button>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
          <!-- <el-button icon="el-icon-download" @click="$refs.xTable.openExport()" circle></el-button> -->
        </template>
      </vxe-toolbar>
      <div class="aui-card-list-body-table">
      <vxe-table ref="xTable" :loading="dataListLoading" class="vxe-table-element" auto-resize
        @select-change="dataListSelectionChangeHandleVex" @select-all="dataListSelectionAllChangeHandleVex"
        :customs.sync="customColumns" :data="dataList" max-height="auto">
        <vxe-table-column type="checkbox" width="60"></vxe-table-column>
        <vxe-table-column field="snippetCode" title="片段编码">
        </vxe-table-column>
        <vxe-table-column field="snippetName" title="片段名称">
        </vxe-table-column>
        <vxe-table-column field="snippetType" title="片段类型" width="120">
          <template slot-scope="scope">
            {{$getDictLabel('GEN_TEMP_APP_TYPE', scope.row.snippetType)}}
          </template>
        </vxe-table-column>
        <vxe-table-column field="updater" title="更新者" width="120" align="center">
        </vxe-table-column>
        <vxe-table-column field="updateDate" title="更新时间" width="140" align="center">
        </vxe-table-column>
        <vxe-table-column title="handle" fixed="right" width="140" align="center">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('gen:genTableTemplate:update')" type="text" icon="el-icon-edit" size="small"
              @click="addOrUpdateHandle(scope.row)">{{ $t('update') }}
            </el-button>
            <el-button v-if="$hasPermission('gen:genTableTemplate:delete')" type="text" icon="el-icon-delete"
              size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}
            </el-button>
          </template>
        </vxe-table-column>
      </vxe-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
        layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      </div>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </el-card>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './genCodeSnippet-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      searchShow: true,
      mixinViewModuleOptions: {
        getDataListURL: '/gen/genCodeSnippet/page',
        getDataListIsPage: true,
        deleteURL: '/gen/genCodeSnippet',
        deleteIsBatch: true,
        exportURL: '/gen/genCodeSnippet/export'
      },
      dataForm: {
        snippetCode: '',
        snippetName: '',
        snippetType: ''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  methods: {
    // 新增 / 修改
    addOrUpdateHandle (row) {
      let id
      if (row) {
        id = row.id
      }
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.id = id
        this.$refs.addOrUpdate.init()
      })
    }
  }
}
</script>
